<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>替换网页元素</title>
</head>
<body>
    <div id="div1">
        <p>我是第一行内容 </p> 
        <p id="p2">我是第二行内容</p>
        <p>我是第三行内容</p>
        <p>我是第四行内容</p>
    </div>
    <script>
        function replaceNode() {
        var div1= document.getElementById("div1");
        var p2= document.getElementById("p2");
        var div2= document.createElement("div");
        var text1= document.createTextNode("javaScript课程");
        div2.appendChild (text1);
        div1.replaceChild(div2, p2);
        }
    </script>
    <input type="button" value="将第二行内容替换为javaScript课程" onclick="replaceNode()"/>
</body>
</html>